jetcrab\bytecode\statements/
try_catch.rs1use crate::ast::Node;
2use crate::vm::instructions::Instruction;
3
4use super::ControlFlowCore;
5
6pub fn generate_try_statement<T>(this: &mut T, node: &Node)
7where
8 T: ControlFlowCore,
9{
10 if let Node::TryStatement(stmt) = node {
11 this.visit_node(&stmt.block);
14
15 if let Some(handler) = &stmt.handler {
17 generate_catch_clause(this, handler);
18 }
19
20 if let Some(finalizer) = &stmt.finalizer {
22 this.visit_node(finalizer);
23 }
24 }
25}
26
27pub fn generate_catch_clause<T>(this: &mut T, node: &Node)
28where
29 T: ControlFlowCore,
30{
31 if let Node::CatchClause(clause) = node {
32 this.visit_node(&clause.param);
35
36 this.visit_node(&clause.body);
38 }
39}
40
41pub fn generate_throw_statement<T>(this: &mut T, node: &Node)
42where
43 T: ControlFlowCore,
44{
45 if let Node::ThrowStatement(stmt) = node {
46 this.visit_node(&stmt.argument);
47 this.instructions().push(Instruction::Throw);
48 }
49}